package com.lovo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class WebConfig extends WebMvcConfigurationSupport {


    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/upload/**").addResourceLocations("file:d:/server/upload/");
        // 解决swagger无法访问
        registry.addResourceHandler("/swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        // 解决swagger的js文件无法访问
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

    }

    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    ///**
    // * 使用session 来拦截器进行拦截
    // * @param registry
    // */
    //@Override
    //protected void addInterceptors(InterceptorRegistry registry) {
    //    registry.addInterceptor(new SessionInterceptor()) //添加需要验证登录用户操作权限的请求
    //            .addPathPatterns("/**")
    //            .excludePathPatterns("/static/**");  //这里可以用registry.addInterceptor添加多个拦截器实例，后面加上匹配模式
    //    super.addInterceptors(registry);//最后将register往这里塞进去就可以了
    //}


}
